package cn.stylefeng.guns.modular.pandian.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.pandian.entity.PandianDetailed;
import cn.stylefeng.guns.modular.pandian.mapper.PandianDetailedMapper;
import cn.stylefeng.guns.modular.pandian.model.params.PandianDetailedParam;
import cn.stylefeng.guns.modular.pandian.model.result.PandianDetailedResult;
import cn.stylefeng.guns.modular.pandian.model.result.PandianJihuaUserResult;
import  cn.stylefeng.guns.modular.pandian.service.PandianDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 盘点库存明细表 服务实现类
 */
@Service
public class PandianDetailedServiceImpl extends ServiceImpl<PandianDetailedMapper, PandianDetailed> implements PandianDetailedService {

    @Override
    public void add(PandianDetailedParam param){
        PandianDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PandianDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PandianDetailedParam param){
        PandianDetailed oldEntity = getOldEntity(param);
        PandianDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PandianDetailedResult findBySpec(PandianDetailedParam param){
        return null;
    }

    @Override
    public List<PandianDetailedResult> findListBySpec(PandianDetailedParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(PandianDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(PandianDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PandianDetailed getOldEntity(PandianDetailedParam param) {
        return this.getById(getKey(param));
    }

    private PandianDetailed getEntity(PandianDetailedParam param) {
        PandianDetailed entity = new PandianDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<PandianDetailedResult> findPanDianPositionListBySpec(PandianDetailedParam pandianDetailedParam,
			Long userId, Long diskId) {
		return this.baseMapper.findPanDianPositionListBySpec(pandianDetailedParam,userId,diskId);
	}

	@Override
	public PandianDetailedResult findPanDianPositionBySpec(PandianDetailedParam pandianDetailedParam, Long userId,
			Long diskId) {
		return this.baseMapper.findPanDianPositionBySpec(pandianDetailedParam,userId,diskId);
	}

	@Override
	public List<PandianDetailedResult> findPanDianGoodsListBySpec(PandianDetailedParam pandianDetailedParam,
			Long userId, Long diskId) {
		return this.baseMapper.findPanDianGoodsListBySpec(pandianDetailedParam,userId,diskId);
	}

	@Override
	public List<PandianDetailedResult> findPanDianTrayListBySpec(PandianDetailedParam pandianDetailedParam, Long userId,
			Long diskId) {
		return this.baseMapper.findPanDianTrayListBySpec(pandianDetailedParam,userId,diskId);
	}

	@Override
	public PandianDetailedResult sumByspec(PandianDetailedParam param) {
		return this.baseMapper.sumByspec(param);
	}

	@Override
	public boolean saveBatchList(List<PandianDetailedParam> addlist) {
		return this.baseMapper.saveBatchList(addlist);
	}

}
